package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.ClassAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.ClassUpdateDTO;
import cn.tedu.blackhorse.pojo.entity.Class;
import cn.tedu.blackhorse.pojo.vo.ClassListItemVO;
import cn.tedu.blackhorse.service.IClassService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/classe")
@Api(tags = "班级表")
@Validated
public class ClassController {

    @Autowired
    private IClassService classService;

    @PostMapping("/addNew")
    @ApiOperation("增加班级")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void>  addNew(ClassAddNewDTO cls){
        log.debug("开始处理新增班级业务");
        classService.insertClass(cls);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除班级")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理删除班级业务");
        classService.deleteClass(id);
        return JsonResult.ok();
    }

    @GetMapping("/")
    @ApiOperation("班级列表")
    @ApiOperationSupport(order = 300)
    public JsonResult<List<ClassListItemVO>> list(){
        log.debug("开始处理班级列表业务");
        List<ClassListItemVO> list = classService.classList();
        return JsonResult.ok(list);
    }

    @PostMapping("/update")
    @ApiOperation("修改班级信息")
    @ApiOperationSupport(order = 400)
    public JsonResult<Void> update( Long id,ClassUpdateDTO cls){
        log.debug("开始处理修改班级信息业务");
        classService.updateById(id,cls);
        return JsonResult.ok();
    }

}
